package com.itcast.peft.entity.report;

import java.util.Arrays;

import com.fasterxml.jackson.annotation.JsonPropertyDescription;

import lombok.Data;

/**
 *  健康评估类
 * @author itheima
 */
@Data
public class HealthAssessmentVo {
    /**
     * 健康风险等级
     */
    @JsonPropertyDescription("下列之一：healthy/caution/risk/danger/severeDanger")
    private String riskLevel;
    /**
     * 健康指数
     */
    private double healthIndex;
    
    public int accuracyScore(HealthAssessmentVo ref) {
        int result = 0;
        var arr = new String[] { "healthy", "caution", "risk", "danger", "severeDanger" };
        // 相临 1分
        if (Math.abs(Arrays.binarySearch(arr, riskLevel) - Arrays.binarySearch(arr, ref.riskLevel)) <= 1) {
            result += 1;
        }
        // 指数误差范围在10以内，记1分
        if (Math.abs(healthIndex - ref.healthIndex) <= 10) {
            result += 1;
        }
        return result;
    }

}